from django.http import HttpResponseRedirect, Http404
from django.shortcuts import render_to_response
from doors.models import *
from doors.forms import *

def index(req):    
    form = DoorForm();
    return render_to_response('index.html', {'doors' : Door.all(), 'form': form})

def save(req):
    if req.method == 'POST':
        form = DoorForm(req.POST)
        if form.is_valid():
            door = form.save()
            door.put()
            return HttpResponseRedirect('/')
        
    return index(req)